<template>
  <!-- Form -->
  <el-card class="box-card" style="text-align: center;display: table-cell;vertical-align: middle">
    <el-button text @click="dialogVisible = true">
      <el-icon :size="60" style="color:#b4b5ff;">
        <Plus/>
      </el-icon>
    </el-button>
  </el-card>
  <el-dialog v-model="dialogVisible" title="发布实验">
    <el-form :model="form" :label-width="formLabelWidth">
      <el-form-item label="实验名称">
        <el-input v-model="form.name" autocomplete="off"/>
      </el-form-item>
      <el-form-item label="实验内容">
        <el-input v-model="form.content" autocomplete="off" type="textarea"/>
      </el-form-item>
      <el-form-item label="截止时间">
        <el-input v-model="form.deadline" autocomplete="off"/>
      </el-form-item>
      <!--      <el-form-item label="截止时间">-->
      <!--        <el-date-picker-->
      <!--            v-model="form.date"-->
      <!--            type="datetime"-->
      <!--            placeholder="选择时间"-->
      <!--            format="YYYY/MM/DD HH:mm:ss"-->
      <!--        />-->
      <!--      </el-form-item>-->
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="dialogVisible = false">取消</el-button>
        <el-button type="primary" @click="announce">
          发布
        </el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script lang="ts" setup>
import {reactive, Ref, ref} from 'vue'
import axios from "axios";
import Experiment from "@/class/Experiment";
import {CourseStore, userStore} from "@/store";

const dialogVisible = ref(false)
const formLabelWidth = '140px'

const userstore = userStore()
const coursestore = CourseStore()
// cid绑定
const form = ref({
  cid: coursestore.course_id,
  tid: userstore.teacher_id,
  deadline: '',
  content: '',
  name: ''
})

const announce = async () => {
  dialogVisible.value = false
  console.log("course_id:" + coursestore.course_id)
  await
      axios.get('/teacher/teacherupexpriment?cid='+coursestore.course_id+"&tid="+userstore.teacher_id+"&deadline="+form.value.deadline
          +"&content="+form.value.content+"&name="+form.value.name,)
          .then(function (res) {
            console.log(res.data)
            console.log(form.value)
          })
  form.value = {
    cid: coursestore.course_id,
    tid: userstore.teacher_id,
    deadline: '',
    content: '',
    name: ''
  }
}
</script>
<style scoped>
.el-button--text {
  margin-right: 15px;
}

.el-select {
  width: 300px;
}

.el-input {
  width: 300px;
}

.dialog-footer button:first-child {
  margin-right: 10px;
}

.text {
  font-size: 14px;
}

.item {
  padding: 18px 0;
}

.box-card {
  width: 400px;
  margin: 40px 20px;
  height: 140px;
}

a {
  text-decoration: none;
  color: #b4b5ff;
}
</style>
